<template>
    <div class="app-container">
      <!--工具栏-->
      <Search :crud="crud">
        <el-form-item label="岗位">
            <el-input v-model="query.jobScope" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="招聘类型">
          <el-select v-model="query.recruitmentType" placeholder="请选择">
            <el-option
              v-for="item in dict.RECRUITMENT_TYPE"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </Search>
      <el-card>
        <div class="head-container">
            <crudOperation :permission="permission">
                <template slot="right">
                    <el-button class="filter-item" size="mini" type="primary" icon="el-icon-plus" @click="handle(null,'new')">新建</el-button>
                    <!-- <el-button class="filter-item" size="mini" type="primary" icon="el-icon-delete" @click="handle(null,'batchDelete')">批量删除</el-button> -->
                </template>
            </crudOperation>
        </div>
        <el-table ref="table" border v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
            <el-table-column type="selection" width="55" align="center" fixed="left"/>
            <el-table-column label="序号" type="index" width="50" align="center"/>
            <el-table-column prop="theme" label="招聘类型" align="center">
              <template slot-scope="scope">
                  <div>{{ showDictValue(scope.row.recruitmentType,dict.RECRUITMENT_TYPE) }}</div>
              </template>
            </el-table-column>
            <el-table-column prop="jobScope" label="岗位" align="center"/>
            <el-table-column prop="newScope" label="薪资范围" align="center"/>
            <el-table-column prop="area" label="办公地点" align="center"/>
            <el-table-column prop="scale" label="规模" align="center"/>
            <el-table-column prop="createdByName" label="创建人" align="center"/>
            <el-table-column prop="createdAtView" label="创建日期" width="200" align="center"/>
            <el-table-column label="操作" align="center" width="200"  fixed="right">
              <template slot-scope="scope">
                  <el-button type="danger" size="mini" @click="handle(scope.row,'delete')">删除</el-button>
                  <el-button type="primary" size="mini" @click="handle(scope.row,'update')">修改</el-button>
              </template>
            </el-table-column>
        </el-table>

        <!--分页组件-->
        <pagination />
      </el-card>
      <InternalRecommendationDialog ref="handbookDialog" @submitSuccess="submitSuccess"></InternalRecommendationDialog>
    </div>
  </template>
  
  <script>
  import crudJob from '@/api/system/job'
  import CRUD, { presenter, header, crud } from '@crud/crud'
  import crudOperation from '@crud/CRUD.operation'
  import pagination from '@crud/Pagination'
  import udOperation from '@crud/UD.operation'
  import Search from '@/components/Search'

  import internalRecommendation from '@/api/inviteJob/internalRecommendation/index'
  import InternalRecommendationDialog from '@/views/inviteJob/internalRecommendation/internalRecommendationDialog.vue'
  import { showDictValue } from '@/utils'
  export default {
    name: 'BrandIntroductionManage',
    components: { crudOperation, pagination, udOperation, Search,InternalRecommendationDialog },
    cruds() {
      return CRUD({
        title: '内部推荐列表',
        url: 'internalRecommendation/list',
        requestMethod: 'post',
        sort: ['jobSort,asc2', 'id,desc'],
        // takingType:'3',
        otherParams:{'takingType':'3'},
        crudMethod: { ...crudJob }
      })
    },
    // mixins: [presenter()],
    mixins: [presenter(), header(), crud()],
    // 数据字典
    dicts: ['RECRUITMENT_TYPE'],
    data() {
      return {
        permission: {
          add: ['admin', 'job:add'],
          edit: ['admin', 'job:edit'],
          del: ['admin', 'job:del']
        }
      }
    },
    methods: {
      showDictValue,
      // 改变状态
      changeEnabled(data, val) {
        product.tbDemoMoldTakingUpdateStatus({id:data.id,isRelease:val}).then(() => {
          this.$notify({ message: '操作成功', type: 'success'});
          this.crud.refresh();
        }).catch(err => {
          data.isRelease = !data.isRelease
          if (data.isRelease=='1') {
            data.isRelease = '0';
          }else{
            data.isRelease = '1';
          }
        })
      },
      // 删除与修改事件
      handle(row,type){
        if (type == 'delete') {//删除
          this.deleteHandle(row);
        }else if (type == 'update') {// 修改
          let forms = JSON.parse(JSON.stringify(row));
          this.$refs.handbookDialog.form = {//forms
            id: forms.id,
            recruitmentType:forms.recruitmentType,//招聘类型
            jobScope:forms.jobScope,
            newScope: forms.newScope,
            content: forms.content,//描述
            area: forms.area,
            scale: forms.scale,
          };
          this.$refs.handbookDialog.isEdit = true;
          this.$refs.handbookDialog.dialogVisible = true;
        }else if (type == 'new') {// 新增
          this.$refs.handbookDialog.form = {
            id: '',
            recruitmentType:'',//招聘类型
            jobScope:'',
            newScope: '',
            content: '',//描述
            area:'',
            scale:'',//规模
          }
          this.$refs.handbookDialog.isEdit = false;
          this.$refs.handbookDialog.dialogVisible = true;
        }else if (type == 'batchDelete') {// 批量删除
          if (this.crud.selections.length==0) {
            this.$notify({ title: '请选择需要删除的数据', type: 'warning' });
            return;
          }
          const idList = [];
          for (let index = 0; index < this.crud.selections.length; index++) {
            const element = this.crud.selections[index];
            idList.push(element.id);
          }
          this.deleteHandle(idList);
        } else {
          
        }
      },
      // 删除
      deleteHandle(params){
        this.$confirm('确定删除吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          internalRecommendation.deleteHandle(params).then((res) => {
                this.$notify({ message: '操作成功', type: 'success'});
                this.crud.refresh()
            }).catch(() => {})
        })
      },
      // 新建取模成功
      submitSuccess(){
        this.crud.refresh();
      }
    }
  }
  </script>
  
  <style rel="stylesheet/scss" lang="scss" scoped>
   ::v-deep .el-input-number .el-input__inner {
      text-align: left;
    }
    .item {
      margin-top: 10px;
      margin-right: 10px;
    }
  </style>
  